home *** CD-ROM | disk | FTP | other *** search
/ Delphi Developer's Kit 1996 / Delphi Developer's Kit 1996.iso / power / dataconv / memoform.pas < prev    next >
Pascal/Delphi Source File  |  1995-12-22  |  4KB  |  178 lines

  1. unit Memoform;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls, Menus, Buttons, ExtCtrls;
  8.  
  9. type
  10.   TFieldAssign = class(TForm)
  11.     ConvFields: TMemo;
  12.     MainMenu1: TMainMenu;
  13.     File1: TMenuItem;
  14.     Load1: TMenuItem;
  15.     Save1: TMenuItem;
  16.     Exit1: TMenuItem;
  17.     OpenDialog1: TOpenDialog;
  18.     SaveDialog1: TSaveDialog;
  19.     Cancel1: TMenuItem;
  20.     Panel1: TPanel;
  21.     BitBtn1: TBitBtn;
  22.     BitBtn2: TBitBtn;
  23.     procedure Save1Click(Sender: TObject);
  24.     procedure Load1Click(Sender: TObject);
  25.     procedure Exit1Click(Sender: TObject);
  26.     procedure Cancel1Click(Sender: TObject);
  27.     procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  28.     procedure BitBtn1Click(Sender: TObject);
  29.   private
  30.     { Private declarations }
  31.   public
  32.     { Public declarations }
  33.   end;
  34.  
  35. var
  36.   FieldAssign: TFieldAssign;
  37.  
  38. implementation
  39.  
  40. uses dbftosql, progform;
  41.  
  42. {$R *.DFM}
  43.  
  44. procedure TFieldAssign.Save1Click(Sender: TObject);
  45. begin
  46.    SaveDialog1.Execute;
  47.    if SaveDialog1.FileName > '' then
  48.      ConvFields.Lines.SaveToFile(SaveDialog1.FileName);
  49. end;
  50.  
  51. procedure TFieldAssign.Load1Click(Sender: TObject);
  52. begin
  53.    OpenDialog1.Execute;
  54.    if OpenDialog1.FileName > '' then
  55.      ConvFields.Lines.LoadFromFile(OpenDialog1.FileName);
  56. end;
  57.  
  58. procedure TFieldAssign.Exit1Click(Sender: TObject);
  59. begin
  60.    ModalResult := IDOK;
  61. end;
  62.  
  63. procedure TFieldAssign.Cancel1Click(Sender: TObject);
  64. begin
  65.    ModalResult := IDCANCEL;
  66. end;
  67.  
  68. procedure TFieldAssign.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  69. begin
  70.    ModalResult := IDCancel;
  71. end;
  72.  
  73. procedure TFieldAssign.BitBtn1Click(Sender: TObject);
  74. var lastcount, ProcCount, ChangeCount, KeyCount, ConvCount : longint;
  75.    text : string;
  76. begin
  77.  
  78.    with Dbf2Sql do begin
  79.  
  80.       DestTable.Active := False;
  81.  
  82.       Dbf2Sql.Abort := False;
  83.  
  84.       DestTable.TableName := DestTableName.Text;
  85.  
  86.       try
  87.          chdir( DestPath.Text );
  88.       except
  89.          Application.HandleException( self );
  90.       end;
  91.  
  92.       DestDataBase.Connected := True;
  93.  
  94.       ConvForm.Gauge1.MinValue := 0;
  95.       ConvForm.Gauge1.MaxValue := SrcTable.RecordCount;
  96.  
  97.       str( SrcTable.RecordCount : 8, text );
  98.       ConvForm.TotalCount.Caption := text;
  99.  
  100.       ConvForm.Gauge1.Progress := 0;
  101.  
  102.       BatchMove.Mappings := FieldAssign.ConvFields.Lines;
  103.  
  104.    { The 50 in the following line means it will do 2% at a time.
  105.      For better speed, this can be changed to a lower number, OR
  106.      BatchMove.RecordCount can be assigned to 0 - that way it will
  107.      convert the whole table at once. }
  108.  
  109.       BatchMove.RecordCount := trunc(ConvForm.Gauge1.MaxValue / 50);
  110.  
  111.       if BatchMove.RecordCount < 5 then
  112.          BatchMove.RecordCount := 5;
  113.  
  114.       ConvForm.BitBtn1.Caption := 'Abort';
  115.  
  116.       LastCount := 1;
  117.       ProcCount := 0;
  118.       ChangeCount := 0;
  119.       Keycount := 0;
  120.       ConvCount := 0;
  121.  
  122.       ConvForm.Show;
  123.  
  124.       try
  125.  
  126.          while (LastCount > 0) and not (SrcTable.EOF) and not (dbf2sql.abort) do begin
  127.  
  128.             DestTable.Active := False;
  129.  
  130.             BatchMove.Execute;
  131.  
  132.             LastCount := BatchMove.MovedCount;
  133.  
  134.             ProcCount := ProcCount + LastCount;
  135.             ChangeCount := ChangeCount + BatchMove.ChangedCount;
  136.             KeyCount := KeyCount + BatchMove.KeyViolCount;
  137.             ConvCount := ConvCount + BatchMove.ProblemCount;
  138.  
  139.             str( ProcCount : 8, text );
  140.             ConvForm.ProcCount.Caption := text;
  141.  
  142.             str( KeyCount : 8, text );
  143.             ConvForm.KeyCount.Caption := text;
  144.  
  145.             str( ConvCount : 8, text );
  146.             ConvForm.ConvCount.Caption := text;
  147.  
  148.             ConvForm.Gauge1.Progress := ConvForm.Gauge1.Progress + lastCount;
  149.  
  150.             ConvForm.ConvCount.Refresh;
  151.             ConvForm.KeyCount.Refresh;
  152.             ConvForm.ProcCount.Refresh;
  153.             ConvForm.Gauge1.Refresh;
  154.  
  155.             SrcTable.MoveBy(LastCount);
  156.             Application.ProcessMessages;
  157.  
  158.          end;
  159.  
  160.       except
  161.  
  162.          Application.HandleException( self );
  163.  
  164.       end;
  165.  
  166.       ConvForm.BitBtn1.Caption := 'Done';
  167.  
  168.       if dbf2sql.abort then
  169.          ShowMessage('Conversion Aborted!');
  170.  
  171.       ConvForm.Hide;
  172.       ConvForm.ShowModal;
  173.    end;
  174.  
  175. end;
  176.  
  177. end.
  178.